package 倒排索引;

import java.util.*;
class tianTian
{
    String name;
    ArrayList<Integer> jiangLi = new ArrayList<>();
    public tianTian(String name,int cnt)
    {
        this.name=name;
        jiangLi.add(cnt);
    }
    public String toString()
    {
        return name+"="+jiangLi.toString();
    }
}
public class NewMain {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int line=1;
        ArrayList<String> jieGe=new ArrayList<>();
        ArrayList<tianTian> chengSS=new ArrayList<>();
        while(true)
        {
            String str= in.nextLine();
            if(str.equals("!!!!!"))
            {
                break;
            }
            jieGe.add(str);
            String[] sss=str.split(" ");
            for (String s : sss) {
                boolean fare=true;
                for (tianTian no : chengSS) {
                    if (no.name.equals(s)) {
                        boolean flag=true;
                        for(Integer cnt:no.jiangLi)
                        {
                            if(cnt==line)
                            {
                                flag=false;
                                break;
                            }
                        }
                        if(flag)
                        {
                            no.jiangLi.add(line);
                        }
                        fare=false;
                        break;
                    }
                }
                if(fare)
                {
                    tianTian wenHT = new tianTian(s,line);
                    chengSS.add(wenHT);
                }
            }
            line++;
        }
        Collections.sort(chengSS, new Comparator<tianTian>() {
            @Override
            public int compare(tianTian o1, tianTian o2) {
                if(o1.name.compareTo(o2.name)>0)
                {
                    return 1;
                }
                return -1;
            }
        });
        for(tianTian jiangli:chengSS)
        {
            System.out.println(jiangli);
        }
        while (in.hasNextLine())
        {
            String str=in.nextLine();
            String[] stt=str.split(" ");
            ArrayList<Integer> momoda=new ArrayList<>();
            for (int i = 0; i < jieGe.size(); i++) {
                String omoxi = jieGe.get(i);
                int ccTV = 0;
                for (String gomogomo : stt) {

                    if (omoxi.contains(gomogomo)) {
                        ccTV++;
                    }
                }
                if (ccTV == stt.length) {
                    momoda.add(i+1);
                }
            }
            if(!momoda.isEmpty())
            {
                System.out.println(momoda);
                for(Integer i:momoda)
                {
                    System.out.println("line "+i+":"+jieGe.get(i-1));
                }
            } else
            {
                System.out.println("found 0 results");
            }
        }
    }
}
